#include<iostream>
#include<string>
using namespace std;
int fun(int x)
{
	if (x == 1)
	{
		cout << 0;
		return 0;
	}
	int i = 0, j = 1,num=1;
	while (x > num)
	{
		num = i + j;
		i = j;
		j = num;
	}
	if ((x - i) > (j - x))
		cout << j - x;
	else
		cout << x - i;
}
int main()
{
	int m;
	cin >> m;
	fun(m);
}

